/*analyses for Oneal and Tir's "Does the Diversionary Use of Force Threaten the
Democratic Peace," International Studies Quarterly, TAble 1: 4-7-2006*/

set mem 220m

use c:\growth\isqfinal\otdirect

desc
summ

/*make minimum value of caprat positive and generate square*/
replace lncaprat=lncaprat+10.3
gen lncapsq=lncaprat^2

/*make sure growth not measured across leaders*/
#del ;
sort state target year;
quietly by state target: gen grow_stldr=grow_st if (leadid_st==leadid_st[_n-1] &
      leadid_st==leadid_st[_n-2]);
quietly by state target: gen grow_tgtldr=grow_tgt if (leadid_tgt==leadid_tgt[_n-1] &
      leadid_tgt==leadid_tgt[_n-2]);
#del cr
drop grow_st grow_tgt leadid*

/*identify year before election*/
by state target: gen el_lag1=elect_st[_n-1] if year-1==year[_n-1]

/*identify year after election*/
by state target: gen el_lead1=elect_st[_n+1] if year+1==year[_n+1]

gen logdist=ln(distance)
drop distance

/*create control for number of states in system for non-rel dyads*/
gen systsize=-ln(numstate) if ~(dircont==1 | majpower==1)
replace systsize=0 if systsize==.

gen dyadid=(1000*state)+target
drop state*

drop if depend>1

/*drop exactly zero growth b/c result of interpol of rgdppc*/
drop if grow_stldr==0

/*all dyads, fatal disputes in year t+1, originator + side A*/
#del ;
gen demXgrow=grow_stldr if democ_st_cg==1 & democ_st~=.;
replace demXgrow=0 if demXgrow==. & grow_stldr~=.;

gen dmtgt_grow=grow_tgtldr if democ_tgt>6 & democ_tgt~=.;
replace dmtgt_grow=0 if dmtgt_grow==. & grow_tgtldr~=.;

/*TABLE 1, COLUMN 1*/
logit finitsda democ_st democ_tgt depend lncaprat lncapsq allies dircont
      logdist majpower systsize pyfatA _spl*, nolog cluster(dyadid);
testparm lncap*;

/*TABLE 1, COLUMN 2*/
logit finitsda democ_st democ_tgt depend grow_stldr lncaprat lncapsq allies dircont
      logdist majpower systsize pyfatA _spl*, nolog cluster(dyadid);  
testparm lncap*;

/*TABLE 1, COLUMN 3*/
logit finitsda democ_st democ_tgt depend grow_stldr demXgrow lncaprat lncapsq allies
      dircont logdist majpower systsize pyfatA _spl*, nolog cluster(dyadid);  

/*reported in text only re Smith 1996*/
logit finitsda democ_st democ_tgt depend grow_stldr demXgrow dmtgt_grow lncaprat
      lncapsq allies dircont logdist majpower systsize pyfatA _spl*, nolog
      cluster(dyadid);  

/*TABLE 1, COLUMN 4*/
logit finitsda el_lag1 elect_st el_lead1 democ_st democ_tgt depend 
      demXgrow lncaprat lncapsq allies dircont logdist majpower systsize pyfatA
      _spl*, nolog cluster(dyadid); 

exit;














/*Table 1 revised to include grow_stldr: 11-17-05*/

/*Table 1 revised to use lncaprat and lncaprat^2: 9-12-05*/

/*rerun 9-27-04 with final data*/

/*analysis of directed dyads, fatal MIDs, all dyads, using new leadership data;
cases w/ exactly zero growth excluded b/c extrapolations in rgdp data:
9-10-2004*/

set mem 220m

use dir92704

desc
summ

drop if democ_st==.
drop if democ_tgt==.

/*make minimum value of caprat positive and generate square*/
replace lncaprat=lncaprat+10.3
gen lncapsq=lncaprat^2

/*make sure growth not measured across leaders*/
#del ;
sort state target year;
quietly by state target: gen grow_stldr=grow_st if (leadid_st==leadid_st[_n-1] &
      leadid_st==leadid_st[_n-2]);
quietly by state target: gen grow_tgtldr=grow_tgt if (leadid_tgt==leadid_tgt[_n-1] &
      leadid_tgt==leadid_tgt[_n-2]);
#del cr
drop leadid* grow_st grow_tgt

gen logdist=ln(distance)
drop distance

gen dyadid=(1000*state)+target
drop state*

drop if depend>1

/*drop exactly zero growth b/c result of interpol of rgdppc*/
drop if grow_stldr==0

/*all dyads, fatal disputes in year t+1, originator + side A*/
#del ;

/*TABLE 1, COLUMN 1*/
logit finitsda democ_st democ_tgt depend lncaprat lncapsq allies dircont
      logdist majpower systsize pyfatA _spl*, nolog cluster(dyadid);
testparm lncap*;

/*TABLE 1, COLUMN 2*/
logit finitsda democ_st democ_tgt depend grow_stldr lncaprat lncapsq allies dircont
      logdist majpower systsize pyfatA _spl*, nolog cluster(dyadid);  
testparm lncap*;

/*baseline model with restricted sample*/
logit finitsda democ_st democ_tgt depend lncaprat lncapsq allies dircont
      logdist majpower systsize pyfatA _spl* if e(sample)==1, nolog cluster(dyadid);
testparm lncap*;

gen demXgrow=grow_stldr if democ_st_cg==1 & democ_st~=.;
replace demXgrow=0 if demXgrow==. & grow_stldr~=.;

gen dmtgt_grow=grow_tgtldr if democ_tgt>6 & democ_tgt~=.;
replace dmtgt_grow=0 if dmtgt_grow==. & grow_tgtldr~=.;

/*NEW COLUMN 3*/
logit finitsda democ_st democ_tgt depend grow_stldr demXgrow lncaprat lncapsq allies
      dircont logdist majpower systsize pyfatA _spl*, nolog cluster(dyadid);  
gen sample=1 if e(sample)==1;

count if demXgrow<-.0154 & sample==1;
count if democ_st>6 & sample==1;

/*assess Reviewer's 1 concern*/
logit finitsda democ_st_cg democ_tgt depend grow_stldr demXgrow lncaprat lncapsq
      allies dircont logdist majpower systsize pyfatA _spl*, nolog cluster(dyadid); 
count if demXgrow<-.0225 & sample==1;
count if democ_st_cg==1 & sample==1;

/*reported in text only re Smith 1996*/
logit finitsda democ_st democ_tgt depend grow_stldr demXgrow dmtgt_grow lncaprat
      lncapsq allies dircont logdist majpower systsize pyfatA _spl*, nolog
      cluster(dyadid);  

/*TESTS OF ROBUSTNESS, REPORTED IN TEXT OR NOTE*/
/*PRDs ONLY--non-dircont predicts failure perfectly so not included*/
logit finitsda democ_st democ_tgt depend grow_stldr demXgrow lncaprat lncapsq  
      allies logdist majpower systsize pyfatA _spl* if (dircont==1 |              
      majpower==1), nolog cluster(dyadid);  

/*DROP OUTLIERS ON GROWTH*/
logit finitsda democ_st democ_tgt depend grow_stldr demXgrow lncaprat lncapsq allies
      dircont logdist majpower systsize pyfatA _spl* if abs(demXgrow)<.15, nolog
      cluster(dyadid);  

drop rgdp96* sample autoc* mixed*;

/*USE KING'S RARE LOGIT*/
relogit finitsda democ_st democ_tgt depend grow_stldr demXgrow lncaprat lncapsq
      allies dircont logdist majpower systsize pyfatA _spl*, cluster(dyadid);  

/*ANALYSIS WITH MINIMUM CO-VARIATES*/
logit finitsda grow_stldr demXgrow dircont logdist systsize pyfatA _spl*,
      nolog cluster(dyadid);  

/*ANALYSIS WITH POST-WW2 DATA ONLY*/
logit finitsda democ_st democ_tgt depend grow_stldr demXgrow lncaprat lncapsq allies
      dircont logdist majpower systsize pyfatA _spl* if year>1945, nolog
      cluster(dyadid);  

exit;
